#ifndef __CHANNEL_HPP__
#define __CHANNEL_HPP__
#include <iostream>

#include <functional>
#include <unistd.h>
#include <sys/wait.h>
#include <cstdlib>
#include <vector>
#include "task.hpp"

#include <sys/wait.h>
#include <sys/types.h>


using work_t = std::function<void()>;
// 先描述
class Channel
{
private:
    int _wfd;
    std::string _name;
    pid_t _who;

public:
    Channel(int wfd, pid_t who);
    ~Channel();
    std::string &name() { return _name; }
    void send(int cmd)
    {
        ::write(_wfd, &cmd, sizeof cmd);
    }
    void close()
    {
        ::close(_wfd);
        ::waitpid(_who, nullptr, 0);
    }
    pid_t Id() { return getpid(); }
};

Channel::Channel(int wfd, pid_t who) : _wfd(wfd), _who(who)
{
    _name = "channel " + std::to_string(wfd) + "-" + std::to_string(who);
}

Channel::~Channel()
{
}
void Usage(std::string proc) { std::cout << "Usage: " << proc << " process"
                                                                 "- num:"
                                         << std::endl; }

#endif // __CHANNEL_HPP__
